home *** CD-ROM | disk | FTP | other *** search
Java Source | 2002-11-09 | 4.5 KB | 170 lines |
- //
- // The contents of this file are subject to the BadBlue End User License
- // Agreement (the "EULA"); you may not use this file except in
- // compliance with the EULA. You may obtain a copy of the EULA at
- // http://badblue.com/down.htm .
- //
- // Software distributed under the EULA is distributed on an "AS IS" basis,
- // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the EULA
- // for the specific language governing rights and limitations under the
- // EULA.
- //
- // The Initial Developer of this code under the EULA is Working Resources,
- // Inc., Atlanta, GA UNITED STATES. All Rights Reserved.
- //
-
- //
- package ShareOffice;
-
- //
- import java.net.*;
- import java.io.*;
- import ShareOffice.HTTPGet;
- import ShareOffice.SOinit;
-
- //
- public class SOaccess extends SOinit {
- //
- public SOaccess() {
- }
- // Retrieve Access table or query over specified number of rows.
- // Inputs:
- // sAddr: address of BadBlue server (e.g., "127.0.0.1:8080")
- // sPath: path of shared file in EXT.INI file (e.g., "path3")
- // sFile: name of Excel file to examine (e.g., "invoice.xls")
- // sTable: name of table or query to retrieve
- // nRowStart: row number to start fetching (zero-based counting)
- // nRows: number of rows to fetch
- // sUser: (optional) user-name to get access to file
- // sPassword: (optional) password to get access to file
- // Outputs:
- // sData[][]: two-dimensional array returned with data
- // (if error occurs, array will be 1x1 and contain an
- // error message)
- //
- public String[][] GetAccessData(
- String sAddr,
- String sPath,
- String sFile,
- String sTable,
- int nRowStart,
- int nRows,
- String sUser,
- String sPassword
- ) {
- String[][] aasData;
- String sError = "";
- try {
-
- // General setup.
- //
- int i, j, bOutOfData;
- int nColumns = 255;
- int nCursor, nCursor2, nCursorEOC;
- String sTemp, sVal, sTemp2;
- aasData = new String[nRows][255];
-
- // Construct the URL and read it.
- //
- String sURL =
- "http://"+sAddr+"/ext.dll?MfcISAPICommand=LoadPage&"+
- "page=mdb.htx&a0=/get/"+sPath+"/"+URLEncoder.encode(sFile, "UTF-8")+
- "&a1="+URLEncoder.encode(sTable, "UTF-8")+"&a2=V&"+
- "a3=&a4="+Integer.toString(nRowStart)+
- "&a8="+Integer.toString(nRows);
- HTTPGet h = new HTTPGet();
- String sPage;
- if (sUser.length() > 0) {
- sPage = h.Read(sURL, sUser, sPassword);
- } else {
- sPage = h.Read(sURL);
- }
-
- // Skip past table name.
- //
- sTemp = "<td class=fXL";
- if ((nCursor = sPage.indexOf(sTemp)) > 0) {
- sPage = sPage.substring(nCursor + sTemp.length());
- }
-
- // Rip through multiple rows of data...
- //
- for (i = bOutOfData = 0; i < nRows; i++) {
- for (j = 0; j < nColumns; j++) {
- //
- sTemp = "<td class=fXL";
- if ((nCursor = sPage.indexOf(sTemp)) < 0) {
- bOutOfData = 1;
- break;
- }
- //
- if (j > 0 && nColumns == 255) {
- sTemp2 = "</tr";
- nCursorEOC = sPage.indexOf(sTemp2);
- if (nCursorEOC >= 0 && nCursorEOC < nCursor) {
- nColumns = j;
- break;
- }
- }
- //
- nCursor += sTemp.length();
- if ((nCursor = sPage.indexOf(">", nCursor)) < 0) {
- sError = "Invalid template file (3)";
- break;
- }
- nCursor++;
- //
- if (nCursor + 255 > (nCursor2 = sPage.length())) {
- nCursor2--;
- } else {
- nCursor2 = nCursor + 255;
- }
- sVal = sPage.substring(nCursor, nCursor2);
- if ((nCursor2 = sVal.indexOf("<")) >= 0) {
- sVal = sVal.substring(0, nCursor2);
- }
- //
- sPage = sPage.substring(nCursor + nCursor2);
- aasData[i][j] = sVal;
- //
- // System.out.println("A["+Integer.toString(i)+"]["+Integer.toString(j)+"]="+sVal);
- }
- if (bOutOfData != 0 || sError.length() > 0) {
- break;
- }
- sTemp = "</tr";
- if ((nCursor = sPage.indexOf(sTemp)) < 0) {
- sError = "Invalid template file (6)";
- break;
- }
- sPage = sPage.substring(nCursor + sTemp.length());
- }
- if (sError.length() > 0) {
- aasData = new String[1][1];
- aasData[0][0] = "Error: " + sError;
- }
- return (aasData);
-
- // ...end SP.
- //
- } catch (StringIndexOutOfBoundsException e) {
- aasData = new String[1][1];
- aasData[0][0] = "Error: string out of bounds: " + e.getMessage();
- return (aasData);
-
- // ...end SP.
- //
- } catch (Exception e) {
- aasData = new String[1][1];
- aasData[0][0] = "Error: no data available: " + e.getMessage();
- return (aasData);
- }
- }
-
- // Private members.
- //
- }
-
- // <EOF>
- //
-